from django.shortcuts import render

# Create your views here.
from rest_framework import mixins, viewsets
from rest_framework.viewsets import ModelViewSet

from news.models import News
from news.serializers import NewsSerializer
from news.utils import StandardResultsSetPagination


class NewsView(mixins.RetrieveModelMixin,
               mixins.ListModelMixin,
               viewsets.GenericViewSet):
    """
        list:
            活动列表
        retrieve:
            活动详情
    """
    permission_classes = ()
    authentication_classes = ()
    queryset = News.objects.all()
    serializer_class = NewsSerializer
    pagination_class = StandardResultsSetPagination
    filter_fields = ('news_type', )

    def get_queryset(self):
        return News.objects.all().order_by('pubdate')